using System.ComponentModel.DataAnnotations;
using JGSY.CMS.LowCode.Platform.Infrastructure.Services.Notification;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.Models;

/// <summary>
/// 缓存设置映射
/// </summary>
public class CacheSettingsConfiguration
{
    [Required]
    public string Provider { get; set; } = "Redis";
    
    public RedisConfiguration Redis { get; set; } = new();
    public CacheConfiguration Cache { get; set; } = new();
    public SmsServiceOptions Sms { get; set; } = new(); // 使用新的SMS配置
    public UploadConfiguration Upload { get; set; } = new();
    public SecurityConfiguration Security { get; set; } = new();
    public CorsConfiguration Cors { get; set; } = new();
    public ApiConfiguration Api { get; set; } = new();
    public RateLimitConfiguration RateLimit { get; set; } = new();
    public LockedConfiguration Locked { get; set; } = new();
    public PermissionConfiguration Permission { get; set; } = new();
    public ExtensionConfiguration Extension { get; set; } = new();
    public MongoDbConfiguration MongoDb { get; set; } = new();
    public ClickHouseConfiguration ClickHouse { get; set; } = new();
}

/// <summary>
/// Redis 配置
/// </summary>
public class RedisConfiguration
{
    [Required]
    public string ConnectionString { get; set; } = "localhost:6379";
    
    public string DefaultExpiration { get; set; } = "00:15:00";
    public string Password { get; set; } = string.Empty;
    public int Database { get; set; } = 0;
    public int MaxRetries { get; set; } = 3;
    public int RetryDelay { get; set; } = 1000;
    public int ConnectionTimeout { get; set; } = 5000;
    public int CommandTimeout { get; set; } = 3000;
    
    /// <summary>
    /// 获取默认过期时间
    /// </summary>
    /// <returns>TimeSpan</returns>
    public TimeSpan GetDefaultExpirationTimeSpan()
    {
        return TimeSpan.TryParse(DefaultExpiration, out var result) ? result : TimeSpan.FromMinutes(15);
    }
}

/// <summary>
/// 缓存配置
/// </summary>
public class CacheConfiguration
{
    public string Type { get; set; } = "memory";
    public bool TestEnabled { get; set; } = true;
    public int TestTTL { get; set; } = 60;
    public string TestKeyPrefix { get; set; } = "cms_test_";
    
    public RedisConfiguration Redis { get; set; } = new();
    public MemcachedConfiguration Memcached { get; set; } = new();
    public DragonflyConfiguration Dragonfly { get; set; } = new();
}

/// <summary>
/// Memcached 配置
/// </summary>
public class MemcachedConfiguration
{
    public List<MemcachedServerConfiguration> Servers { get; set; } = new()
    {
        new() { Host = "localhost", Port = 11211 }
    };
    public int ConnectionTimeout { get; set; } = 5000;
}

/// <summary>
/// Memcached 服务器配置
/// </summary>
public class MemcachedServerConfiguration
{
    public string Host { get; set; } = "localhost";
    public int Port { get; set; } = 11211;
}

/// <summary>
/// Dragonfly 配置
/// </summary>
public class DragonflyConfiguration
{
    public string Url { get; set; } = "redis://localhost:6380";
    public int ConnectionTimeout { get; set; } = 5000;
}
